<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<?php
include 'header.php';
include 'menu.php';
?>
</head>

<body>
<br><br><br>
<?php

$logrequest=$_GET['logrequest'];
$URLname=$_GET['name'];
$configfile="/etc/opt/fbc/fbc.xml";
$xml = simplexml_load_file($configfile);


//Function is to create log selector later in the page:

function LogFileSelector($formname = '', $options = array(), $logrequest, $URLname) 
{
    echo '<select name="'.$formname.'" onchange="MM_jumpMenu(\'parent\',this,0)">';
    foreach ($options as $option => $value) {
    	echo '<option value="objectstatus.php?logrequest='.$value.'&name='.$URLname.'">'.$value.'</option>';
    }
    
	echo '</select>';

}
//End of function

if ($URLname == "global")
{

	$configfile="/etc/opt/fbc/fbc.xml";
	$xml = simplexml_load_file($configfile);
	$lockfile = '/etc/opt/fbc/fbc.lock';
	
	$lastrundate = $xml->lastrundate;
	$lastrunstart = $xml->lastrunstart;
	$lastrunend = $xml->lastrunend;
	$Mainlogpath = $xml->logpath;

	if (file_exists($lockfile))
	{
	$running = "Yes";
	}
	else
	{
	$running = "No";
	}

	if (substr($Mainlogpath, -1) == "/"){
	    $logpath = $Mainlogpath;}
	else {
	    $logpath = $Mainlogpath.'/';}

	$loglist = shell_exec("ls -l $logpath | grep -v '^d' | awk '{print $9}'");
	$logfiles = preg_split('/[\r\n]+/', $loglist);

		echo "<b>Freeload Status</b>";
		echo "<p>";	
		echo "<table>";
		echo "<tr><td width='225'><b>Currently Running?</b></td><td>$running</td></tr>";

        echo "<tr><td><b>Last Full Run:</td><td>$lastrundate</b></td></tr>";
        echo "<tr><td><b>Start Time:</td><td>$lastrunstart</b></td></tr>";
        echo "<tr><td><b>End Time:</td><td>$lastrunend</b></td></tr>";
        echo "<tr><td><b>View Log File:</b></td>";
        echo "<td><form name='form' id='form'>";
}

else 
{
	foreach ($xml->server as $server)
	{
	    $name = $server->name;
	    $remotepath = $server->remotepath;
	    $type = $server->type;
	    $currentfulldate = $server->currentfulldate;
	    $currentfullpath = $server->currentfullpath;
	    $restorepath = $server->restorepath;
	    $starttime = $server->starttime;
	    $endtime = $server->endtime;

		$xmllogpath = $xml->logpath;
			
		if($URLname == $name)
		{	
		if (substr($xmllogpath, -1) == "/"){
			$logpath = $xmllogpath.$name.'/';}
		else {
			$logpath = $xmllogpath.'/'.$name.'/';}

		$lockfile = '/etc/opt/fbc/fbc.lock';
 
		if (file_exists($lockfile))
		{
	   		$islock = shell_exec('grep '.$name.' '.$lockfile.'');
			if (isset($islock))
			{
    			$running = "Yes";
			}
			else 
			{
				$running = "No";
			}
		}
		else 
		{
			$running = "No";
		}	
		echo "<b>".$name." Status</b>";
		echo "<p>";
		echo "<table>";

		//Getting log file names, and putting them into array:
		
		$loglist = shell_exec("ls -l $logpath | grep -v '^d' | awk '{print $9}'");
		$logfiles = preg_split('/[\r\n]+/', $loglist);

		/*	

		//Function is to create log selector later in the page:
		function LogFileSelector($formname = '', $options = array(), $logrequest, $URLname) {
    		echo '<td><select name="'.$formname.'" onchange="MM_jumpMenu(\'parent\',this,0)">';
	    	foreach ($options as $option => $value) {
    	    echo '<option value="status.php?logrequest='.$value.'&name='.$URLname.'">'.$value.'</option>';
    		}
    		echo '</select></td></tr></table>';
		}
		//End of function
		*/
	
		echo "<tr><td width='225'><b>Currently Running?</b></td><td>$running</td></tr>";
		echo "<tr><td><b>Most Current Backup Path: </b></td><td>$restorepath</td></tr>";
		echo "<tr><td><b>Last Full Backup Path: </b></td><td>$currentfullpath</td></tr>";
		
        echo "<tr><td><b>Start Time:</td><td>$starttime</b></td></tr>";
        echo "<tr><td><b>End Time:</td><td>$endtime</b></td></tr>";

		echo "<tr><td><b>View Log File: </b></td>";
		echo "<td><form name='form' id='form'>";
//		echo "</td></tr></table>";
//  		echo '<div align="center">';
	
	//END OF NAME IF STATEMENT!!!
		}
  //END OF XML LOOP!!!
	}

}
//calling log selector function
echo $html = LogFileSelector('logrequest', $logfiles, $logrequest, $URLname);
 echo "</td></tr></table>";
echo "</p>"
?>
</div>
</form>
<p>
  <label for="logView"></label>
  <textarea name="logView" id="logView" cols="72" rows="14"><?php $LogFile = shell_exec('cat '.$logpath.$logrequest.''); echo $LogFile; ?></textarea>
</p>
</body>
</html>
<?php include 'footer.php';
?>
